import QtQuick 1.0

Rectangle {
    signal completed

    width: 800
    height: 600
    color: "black"

    id: introObject

    Item {
        property int txtId : 1
        focus: true

        id: keyboardListener

        function endIntro() {
            completed();
            introObject.destroy();
        }

        Keys.onPressed: {
            if (event.key == Qt.Key_Escape) {
                endIntro();
            }
            else {
                if (txtId < 7) {
                    txtId++;
                    introObject.state = "s" + txtId;
                }
                else {
                    endIntro();
                }
            }
        }
    }

    Text {
        id: txt

        font.family: artifika.name
        color: "white"
        font.pixelSize: 24
        verticalAlignment: Text.AlignVCenter
        horizontalAlignment: Text.AlignHCenter
        anchors.fill: parent
        anchors.leftMargin: 20
        anchors.rightMargin: 20
        wrapMode: "WordWrap"

        onOpacityChanged: {
            if (opacity == 0) {
                fadeIn.running = true;
            }
        }

        /*Component.onCompleted: {
            var x = [
                    "A long time ago, before the second sun vanished from this world, " +
                    "the old knowledge was used by men to live longer.",

                    "Upon the death of his body, a man could come back to life. Not only " +
                    "vigour would return to his dead flesh, he would grow stronger.",

                    "Life was prolonged by drinking the Elixir of Life: a potion made by " +
                    "transmutating different types of ingredients.",

                    "This rare recipe is known by few, and those in the Dark, deluded by immortality " +
                    "chase the ones who know it, and thorture them in order to acquire the information.",

                    "Most of the Alchemists with this ability were captured and killed for refusing to speak.",

                    "The few ones left hide themselves, seeking the now lacking items to prepare the potion " +
                    "that will allow them to live.",

                    "How long more will it last?"
                ];


        }*/
    }

    state: "s1";

    states: [
        State {
            name: "s1"
            PropertyChanges {
                target: txt;
                text: "A long time ago, before the second sun vanished from this world, " +
                       "the old knowledge was used by men to live longer.";
                opacity: 0
            }
        },
        State {
            name: "s2"
            PropertyChanges {
                target: txt;
                text: "Upon the death of his body, a man could come back to life. Not only " +
                       "vigour would return to his dead flesh, he would grow stronger.";
                opacity: 0
            }
        },
        State {
            name: "s3"
            PropertyChanges {
                target: txt;
                text: "Life was prolonged by drinking the Elixir of Life: a potion made by " +
                       "transmutating different types of ingredients.";
                opacity: 0
            }
        },
        State {
            name: "s4"
            PropertyChanges {
                target: txt;
                text: "This rare recipe is known by few, and those in the Dark, deluded by immortality " +
                       "chase the ones who know it, and thorture them in order to acquire the information.";
                opacity: 0
            }
        },
        State {
            name: "s5"
            PropertyChanges {
                target: txt;
                text: "Most of the Alchemists with this ability " +
                      "were captured and killed for refusing to speak.";
                opacity: 0
            }
        },
        State {
            name: "s6"
            PropertyChanges {
                target: txt;
                text: "The few ones left hide themselves, seeking the now lacking items to prepare the potion " +
                       "that will allow them to live.";
                opacity: 0
            }
        },
        State {
            name: "s7"
            PropertyChanges {
                target: txt;
                text: "How long " +
                      "more will it last?";
                opacity: 0
            }
        }
    ]

    NumberAnimation {
        id: fadeIn

        target: txt
        property: "opacity"
        to: 1
        duration: 1500

        running: true
    }

    transitions: Transition {
        NumberAnimation{
            property: "opacity"
            easing.type: Easing.InOutQuad
            duration: 1500
        }
    }

}
